package run.theo.mallorder.config;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * project name: IntelliJ IDEA
 * Date: 2022/10/17 21:37
 *
 * @PackageName: run.theo.mallorder.config
 * @ClassName: RequestOriginParserDefinition
 * @Author: Theo
 * @Version:
 * @Description:
 */
//@Component
public class RequestOriginParserDefinition implements RequestOriginParser {

    //定于区分来源：通过request域获取渠道来源标识
    //然后 交给流控应用 进行匹配
    @Override
    public String parseOrigin(HttpServletRequest httpServletRequest) {
        String serviceName = httpServletRequest.getParameter("serviceName");
        if (StringUtil.isNullOrEmpty(serviceName))
            throw new RuntimeException("serviceName is empty");
        return serviceName;
    }
}
